function removeElement(nums, val) {
    let fastKey = 0, slowKey = 0
    while(fastKey < nums.length) {
        if(nums[fastKey] !== val) {
            nums[slowKey] = nums[fastKey]
            slowKey++
        }
        fastKey++
    }
    return slowKey
}

console.log(removeElement([1,2,3,3,2,1,2,3,4,5,6,7,22,33,0], 2))